<?php
class Ads extends CActiveRecord
{
  public $verifyCode;
  public $upload;
  
  const STATUS_PENDING = 0;
  const STATUS_APPROVED = 1;
  const STATUS_REJECT = 2;

	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Ads the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'ads';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
      array('status, verifyCode, created_at, modified_at', 'safe'),
			array('name, email, phone, package, website, picture', 'required'),
			array('name, email, phone, package', 'length', 'max'=>500),
      array('upload', 'file', 'types' => 'jpg, png, gif, swf', 'allowEmpty' => false, 'on' => 'create'),
			array('website', 'length', 'max'=>2000),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, email, phone, package, website, picture, created_at, modified_at', 'safe', 'on'=>'search'),
      array('verifyCode', 'CaptchaExtendedValidator', 'allowEmpty'=>!CCaptcha::checkRequirements(), 'on' => 'create'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Nama',
			'email' => 'Email',
			'phone' => 'No telepon / HP',
			'package' => 'Paket',
			'website' => 'Website',
			'picture' => 'File gambar',
			'created_at' => 'Created At',
			'modified_at' => 'Modified At',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('package',$this->package,true);
		$criteria->compare('website',$this->website,true);
		$criteria->compare('picture',$this->picture,true);
		$criteria->compare('created_at',$this->created_at,true);
		$criteria->compare('modified_at',$this->modified_at,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}